package org.deri.odhd.buses.resources;

import java.io.IOException;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import org.deri.odhd.buses.index.JourneyManager;
import org.deri.odhd.buses.model.Journey;
import org.deri.odhd.buses.util.JsonUtil;

@Path("/journey")
public class JourneyCollection {
	
	private JourneyManager manager;
	
	@Path("/day/{day}/from/{from}/to/{to}")
	@GET
	@Produces("text/json")
	public String find(@PathParam("day") String day, @PathParam("from") String from,
			@PathParam("to") String to) throws IOException{
		List<Journey> journeysList = manager.findJourneys(day, from, to);
		return JsonUtil.jsonize(journeysList).toString();
	}
	
	public JourneyCollection() throws IOException{
		this.manager = new JourneyManager();
	}
	
	public void setJourneyManager(JourneyManager manager){
		this.manager = manager;
	}
}
